﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using System.Configuration;

namespace SmartSapce.ServiceLocation
{
    public class ServiceLocator
    {
        public static IUnityContainer s_unityContainer;

        private ServiceLocator()
        {
        }

        private static void Initiate()
        {
            s_unityContainer = new UnityContainer();
            UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection(UnityConfigurationSection.SectionName);
            section.Configure(s_unityContainer);
        }

        public static T Get<T>()
        {
            if (s_unityContainer == null)
            {
                Initiate();
            }
            return s_unityContainer.Resolve<T>();
        }

        public static T Get<T>(string name)
        {
            if (s_unityContainer == null)
            {
                Initiate();
            }
            return s_unityContainer.Resolve<T>(name);
        }
    }
}
